package flc.ast.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.activity.CalculatorActivity;
import flc.ast.activity.FlashlightActivity;
import flc.ast.activity.NoiseActivity;
import flc.ast.activity.TranslateActivity;
import flc.ast.activity.TurntableActivity;
import flc.ast.databinding.FragmentDailyToolBinding;
import flc.ast.utils.AppSpUtils;
import flc.ast.utils.Content;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.SPUtil;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link DailyToolFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class DailyToolFragment extends BaseNoModelFragment<FragmentDailyToolBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_daily_tool;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.ivTurntable.setOnClickListener(this);
        mDataBinding.tvNoiseDetection.setOnClickListener(this);
        mDataBinding.tvCalculator.setOnClickListener(this);
        mDataBinding.tvFlashlight.setOnClickListener(this);
        mDataBinding.tvTranslator.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivTurntable://转盘决定器
                startActivity(TurntableActivity.class);
                break;
            case R.id.tvNoiseDetection://噪音检测
                startActivity(NoiseActivity.class);
                break;
            case R.id.tvCalculator://计算器
                startActivity(CalculatorActivity.class);
                break;
            case R.id.tvFlashlight://手电筒
                startActivity(FlashlightActivity.class);
                break;
            case R.id.tvTranslator://翻译器
                startActivity(TranslateActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        boolean isInit = SPUtil.getBoolean(mContext, Content.TURNTABLE_IS_INIT, false);
        if (!isInit) {
            List<String> list = new ArrayList<>();
            String[] data = getResources().getStringArray(R.array.turntable_data);
            for (String datum : data) {
                list.add(datum);
            }
            AppSpUtils.saveTurntableList(list);
        }
    }
}